<template>
 <van-datetime-picker
        v-model="currentDate"
        type="date"
        title="选择年月日"
        :min-date="minDate"
        :max-date="maxDate"
        @cancel="$emit('close')"
        @confirm="confirm"
      />
</template>

<script>
import dayJs from 'dayjs'
import { Toast } from 'vant'
import { toedituserinfo } from '@/api/getverify'
export default {
  data () {
    return {
      minDate: new Date('1900-01-01'),
      maxDate: new Date(),
      currentDate: new Date()
    }
  },
  props: {
    value: {
      type: String,
      required: true
    }
  },

  created () {
    this.currentDate = new Date(this.value)
  },

  methods: {
    async  confirm (val) {
      const timeFormat = dayJs(val).format('YYYY-MM-DD')
      Toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: '加载中'
      })

      try {
        await toedituserinfo({
          birthday: this.timeFormat
        })
        Toast.success('更新成功')
        this.$emit('input', timeFormat)
        this.$emit('close')
      } catch (error) {
        Toast.fail('更新失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
